﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class ForgotPassword : System.Web.UI.Page
{
    private System.Data.SqlClient.SqlDataReader rd;
    protected void Page_Load(object sender, EventArgs e)
    {

    }
    protected void btn_for_pass_Click(object sender, EventArgs e)
    {
        string c = txt_email.Text;

        string query ="select UserName,Password from UserDetails where Email ='" + c + "' and UserName='" + txt_user_name.Text + "'";
        rd = ConnectionManager.ExecuteReader(query);

        if (rd.Read() == true)
        {
            string pass = rd["Password"].ToString();
            var fromAddress = "mz.testingid@gmail.com"; // any address where the email will be sending 
            var toAddress = c;// this is member email address. 
            const string fromPassword = "murtaza123";  //Password of your gmail address 

            // Passing the values and make a email formate to display 
            string subject = "forgot password"; ;
            string body = "From: " + "Tech Freakz" + "\n";
            body += "Email: " + "mz.testingid@gmail.com" + "\n";
            body += "User name :" + txt_user_name.Text + "\n";
            body += "Password: " + pass + "\n";


            var smtp = new System.Net.Mail.SmtpClient();
            {
                smtp.Host = "smtp.gmail.com";
                smtp.Port = 587;
                smtp.EnableSsl = true;
                smtp.DeliveryMethod = System.Net.Mail.SmtpDeliveryMethod.Network;
                smtp.Credentials = new System.Net.NetworkCredential(fromAddress, fromPassword);
                smtp.Timeout = 20000;
            }
            smtp.Send(fromAddress, toAddress, subject, body);
            ScriptManager.RegisterStartupScript(this, this.GetType(), "alertmessage", "javascript:alert('your password is send on " + c + "  ')", true);
            Response.Redirect("Login.aspx");
        }
        else
        {
            //Response.Write("invalid email id");
            ScriptManager.RegisterStartupScript(this, this.GetType(), "alertmessage", "javascript:alert('Invalid Email Id ')", true);
            txt_email.Text = "";
        }
    }
}